<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/6/26
 * Time: 14:03
 */

namespace common\models\Service;



use common\models\Cache;
use common\models\DAO\Ad;

class AdService {
    /*
     * 通过positionid获取banner信息
     */
    public static function getBanner($id){
        $cacheName = 'banner_'.$id;
        $cache = Cache::get($cacheName);
        if($cache)
            return $cache;
        $ad = Ad::find()->where(array('positionID'=>$id, 'status'=>1))->all();
        $return = array();
        $imgPrefix = \Yii::$app->params['imgPrefix'];
        if($ad){
            foreach($ad as $v){
                $list['url'] = $v['url'];
                $list['target'] = $v['target'];
                $list['content'] = $imgPrefix .$v['content'];
                $return[] = $list;
            }
        }
        Cache::set($cacheName, $return);
        return $return;
    }
}